#include <bits/stdc++.h>
using namespace std;
const int N = 10;

int n;
vector<int> path;
bool st[N];

void dfs(int pos)
{
	if(pos == n + 1)
	{
		for(auto &e : path) printf("%5d", e);
		cout << endl;
		return;
	}

	for(int i = 1;i <= n;i ++)
	{
		if(!st[i])
		{
			st[i] = true;
			path.push_back(i);
			dfs(pos + 1);
			st[i] = false;
			path.pop_back();
		}
	}
}

int main()
{
	cin >> n;
	dfs(1);
	return 0;
}